package hot100;

import com.sun.org.apache.bcel.internal.generic.IF_ACMPEQ;

public class Solution540 {
    public int singleNonDuplicate(int[] nums) {
        int i = 0;
        int j = nums.length - 1;
        while (i < j) {
            int mid = (i + j) >> 1;
            if (mid % 2 == 0) {
                if (mid + 1 < nums.length && nums[mid] == nums[mid + 1]) i = mid + 1;
                else j = mid;
            } else {
                if (mid - 1 >= 0 && nums[mid] == nums[mid - 1]) i = mid + 1;
                else j = mid;
            }
        }
        return nums[i];
    }
}
